package edu.ncsu.csc326.coffeemaker;

import edu.ncsu.csc326.coffeemaker.exceptions.InventoryException;
import junit.framework.TestCase;

/**
 * 
 * @author Sarah Heckman
 *
 * Unit tests for CoffeeMaker class.
 */
public class CoffeeMakerTestJunit3 extends TestCase {
	
	private CoffeeMaker cm;
	private Recipe r1;
	private Recipe r2;
	private Recipe r3;
	private Recipe r4;

	protected void setUp() throws Exception {
		cm = new CoffeeMaker();
		
		//Set up for r1
		r1 = new Recipe();
		r1.setName("Coffee");
		r1.setAmtChocolate("0");
		r1.setAmtCoffee("3");
		r1.setAmtMilk("1");
		r1.setAmtSugar("1");
		r1.setPrice("50");
		
		//Set up for r2
		r2 = new Recipe();
		r2.setName("Mocha");
		r2.setAmtChocolate("20");
		r2.setAmtCoffee("3");
		r2.setAmtMilk("1");
		r2.setAmtSugar("1");
		r2.setPrice("75");
		
		//Set up for r3
		r3 = new Recipe();
		r3.setName("Latte");
		r3.setAmtChocolate("0");
		r3.setAmtCoffee("3");
		r3.setAmtMilk("3");
		r3.setAmtSugar("1");
		r3.setPrice("100");
		
		//Set up for r4
		r4 = new Recipe();
		r4.setName("Hot Chocolate");
		r4.setAmtChocolate("4");
		r4.setAmtCoffee("0");
		r4.setAmtMilk("1");
		r4.setAmtSugar("1");
		r4.setPrice("65");
		
		super.setUp();
	}
	
	public void testAddInventory() {
		try {
			cm.addInventory("4","7","0","9");
		} catch (InventoryException e) {
			fail("InventoryException should not be thrown");
		}
	}
	
	public void testAddInventoryException() {
		try {
			cm.addInventory("4", "-1", "asdf", "3");
			fail("InventoryException should be thrown");
		} catch (InventoryException e) {
			//success if thrown
		}
	}
	
	public void testMakeCoffee() {
		cm.addRecipe(r1);
		assertEquals(25, cm.makeCoffee(0, 75));
	}

    public void testEditARecipe() {
        cm.addRecipe(r1);
        String name = cm.editRecipe(0, r2);

        if (name == null) {
            fail("Name should be the name of the edited recipe");
        }

        if (!name.equals(r1.getName())) {
            fail("Name should equal the name of the edited recipe");
        }

        Recipe editedRecipe = cm.getRecipes()[0];

        boolean recipeName = editedRecipe.getName().equals(r1.getName());

        if (!recipeName) {
            fail("Name of the Receipe is not the same as before");
        }

        boolean setAmtChocolate = editedRecipe.getAmtChocolate() == r2.getAmtChocolate();
        boolean setAmtCoffee = editedRecipe.getAmtCoffee() == r2.getAmtChocolate();
        boolean setAmtMilk = editedRecipe.getAmtMilk() == r2.getAmtMilk();
        boolean setAmtSugar = editedRecipe.getAmtSugar() == r2.getAmtSugar();
        boolean setPrice = editedRecipe.getPrice() == r2.getPrice();

        if (!(setAmtChocolate && setAmtCoffee && setAmtMilk && setAmtSugar && setPrice)) {
            fail("Recipe was not edited");
        }

    }
}
